﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.IO;
using System.Text;
using System.Windows.Forms;

using DevComponents.DotNetBar;


namespace ZhimeiSoft.CharmManager.Client.Forms
{
    public class ButtonItemIconHelper
    {
        public static void InitRibbonBar(RibbonBar bar)
        {
            string optionGroupName = "ButtonItem";

            string path = Application.StartupPath + "\\images\\icon\\";
            bool bFirst = true;
            foreach (BaseItem item in bar.Items)
            {
                if (item is ButtonItem)
                {
                    ButtonItem bItem = (ButtonItem)item;
                    bItem.ButtonStyle = eButtonStyle.ImageAndText;
                    bItem.OptionGroup = optionGroupName;

                    string sFlag = item.Tag.ToString().ToUpper();
                    string filename = string.Empty;
                    switch (sFlag)
                    {
                        case "ADD"://新增
                            filename = path + "add.ico";
                            if (File.Exists(filename))
                                bItem.Image = Image.FromFile(filename);
                            break;
                        case "EDIT"://修改
                            filename = path + "edit.ico";
                            if (File.Exists(filename))
                                bItem.Image = Image.FromFile(filename);
                            break;
                        case "DELETE"://删除
                            filename = path + "delete.ico";
                            if (File.Exists(filename))
                                bItem.Image = Image.FromFile(filename);
                            break;
                        case "COMPLETE"://完成
                            filename = path + "complete.ico";
                            if (File.Exists(filename))
                                bItem.Image = Image.FromFile(filename);
                            break;
                        case "REFRESH"://刷新
                            filename = path + "refresh.ico";
                            if (File.Exists(filename))
                                bItem.Image = Image.FromFile(filename);
                            break;
                        case "STOP"://停用
                            filename = path + "stop.ico";
                            if (File.Exists(filename))
                                bItem.Image = Image.FromFile(filename);
                            break;
                        case "REFERENCE"://引用
                            filename = path + "reference.ico";
                            if (File.Exists(filename))
                                bItem.Image = Image.FromFile(filename);
                            break;
                        case "SEARCH"://搜索、查找
                            filename = path + "search.ico";
                            if (File.Exists(filename))
                                bItem.Image = Image.FromFile(filename);
                            break;
                        case "SET"://设置
                            filename = path + "set.ico";
                            if (File.Exists(filename))
                                bItem.Image = Image.FromFile(filename);
                            break;
                    }
                    if (!bFirst)
                        continue;

                    if (bItem.Image != null)
                    {
                        bar.Height = 35;
                    }
                    else
                    {
                        bar.Height = 30;
                    }
                    bFirst = false;
                }
            }
        }
    }
}
